#pragma once
#include <base_definition.h>

#define EI_NIDENT (16)

typedef struct
{
    char e_ident[EI_NIDENT]; /* Magic number and other info */
    u16 e_type;              /* Object file type */
    u16 e_machine;           /* Architecture */
    u32 e_version;           /* Object file version */
    u64 e_entry;             /* Entry point virtual address */
    u64 e_phoff;             /* Program header table file offset */
    u64 e_shoff;             /* Section header table file offset */
    u32 e_flags;             /* Processor-specific flags */
    u16 e_ehsize;            /* ELF header size in bytes */
    u16 e_phentsize;         /* Program header table entry size */
    u16 e_phnum;             /* Program header table entry count */
    u16 e_shentsize;         /* Section header table entry size */
    u16 e_shnum;             /* Section header table entry count */
    u16 e_shstrndx;          /* Section header string table index */
} Elf64_Ehdr;

#define IDENT_STR ("\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\2\0\76\0\1\0\0")
#define IDENT_LEN (23)

typedef struct
{
    u32 p_type;
    u32 p_flags;
    u64 p_offset;
    u64 p_vaddr;
    u64 p_paddr;
    u64 p_filesz;
    u64 p_memsz;
    u64 p_align;
} Elf64_Phdr;

/* Legal values for p_type (segment type).  */

#define PT_NULL 0                  /* Program header table entry unused */
#define PT_LOAD 1                  /* Loadable program segment */
#define PT_DYNAMIC 2               /* Dynamic linking information */
#define PT_INTERP 3                /* Program interpreter */
#define PT_NOTE 4                  /* Auxiliary information */
#define PT_SHLIB 5                 /* Reserved */
#define PT_PHDR 6                  /* Entry for header table itself */
#define PT_TLS 7                   /* Thread-local storage segment */
#define PT_NUM 8                   /* Number of defined types */
#define PT_LOOS 0x60000000         /* Start of OS-specific */
#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */
#define PT_GNU_STACK 0x6474e551    /* Indicates stack executability */
#define PT_GNU_RELRO 0x6474e552    /* Read-only after relocation */
#define PT_LOSUNW 0x6ffffffa
#define PT_SUNWBSS 0x6ffffffa   /* Sun Specific segment */
#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */
#define PT_HISUNW 0x6fffffff
#define PT_HIOS 0x6fffffff   /* End of OS-specific */
#define PT_LOPROC 0x70000000 /* Start of processor-specific */
#define PT_HIPROC 0x7fffffff /* End of processor-specific */
